//
// Created by xili on 2024/8/5 21:28.
// Go big or go home.
//
#include <vector>
#include <stack>

using namespace std;

class Solution {
public:
    vector<int> dailyTemperatures(vector<int> &temperatures) {
        int n = temperatures.size();
        //严格小压大
        stack<int> s;
        vector<int> ans(n, 0);
        for (int i = 0; i < n; i++) {
            while (!s.empty() && temperatures[i] >= temperatures[s.top()]) {
                ans[s.top()] = i - s.top();
                s.pop();
            }
            s.push(i);
        }
        return ans;
    }
};